package dao.impl;

import java.sql.*;

public class BaseDao {
	protected Connection conn = null;
	protected Statement state = null;
	protected PreparedStatement pst= null;
	protected ResultSet rs = null;
	
	// 创建连接基类
	public Connection getConnection(){

		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			String strUrl = "jdbc:mysql://localhost:3306/group4_book?useSSL=false&serverTimezone=UTC";
			conn = DriverManager.getConnection(strUrl,"root","123456");
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
	
	
	// 关闭所有资源
	public void  closeAll(){
		try {
			if(conn != null){
				conn.close();
			}
			if(state != null){
				state = null;
			}
			if(pst != null){
				pst = null;
			}
			if(rs != null){
				rs = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

}
